//sessionStorage.setItem("userID","LectureID1");
function Add_Header_Footer(){
	
	var header = document.getElementById("divheader");
	var footer = document.getElementById("divFooter");
	header.innerHTML="<div id='div_headerLeft'><img src='./img/logo.png'\></div>" +
			"<div id='div_menu'>" +
			"<ul id='ul_menu'>" +
			"<li><a href='index.html'>Home</a></li>" +
			"<li><a href='SubjectList.html'>Subject</a>" +
				"<ul>" +
					"<li><a href='Subject.html'>Add New Subject</a></li>" +
					"<li><a href='SubjectList.html'>View List Subject</a></li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='Topic.html'>Add Topic</a>" +				
			"</li>" +
		
			"<ul>" +
			"<br clear='all'/>" +
			"</div>";
	footer.innerHTML="<a>Coppyright 2013. Group: 1, class: MITM05, Program: MITM </a>";
	

}
function load_page(){
	var IFrame = document.getElementById("iFrameContent");
	var page =gup('page').toLowerCase();
	//alert(page);
	switch (page){
	case 'topic':
		IFrame.src="index1.html";
		break;
	case 'subject':
		IFrame.src="Subjects.html";
		break;
	default:
		IFrame.src="Welcome.html";
		break;
	}
		
}
function gup( name )

{
//  name=name.toUpperCase();
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
//  var results = regex.exec( window.location.href.toUpperCase() );
  var results = regex.exec( window.location.href );
  //alert(results[1]);
  if( results == null )
    return "";
  else
    return results[1];
}

function swapTypeKey(QuestionType1){
	var QuestionType=String(QuestionType1).replace("%20"," ");
	switch (QuestionType){
	case "Multiple Choice":
		QuestionType="1";
		break;
	case "Fillable Blank":
		QuestionType="2";
		break;
	case "Matching Items":
		QuestionType="3";
		break;
	case "Full Text":
		QuestionType="4";
		break;
	}
	return QuestionType;
}
function createobjects(){
	var QuestionType=gup("type");
	var QuestionID=gup("QuestionID");
	topicId=gup("TopicID");
	topic=gup("Topic");
	var numberObjects=document.getElementById("txtNumberObjects").value;
	window.location.href = 'QuestionItem.html?QuestionID='+QuestionID+'&type='+QuestionType+"&numberObjects="+numberObjects+"&TopicID="+topicId+"&Topic="+topic;
}
function GeneralObjects(){
	var numberObjects=gup("numberObjects");
	var QuestionType=swapTypeKey(gup("type"));
	var divControl=document.getElementById("divObjectController");
	var divMultilple=document.getElementById("DivMultipleChoice");
	var divFulltext= document.getElementById("DivFulltext");
	var divFillBlank=document.getElementById("DivFillBlank");
	var divMatchingItems= document.getElementById("DivMatchingItems");
	if (QuestionType==4){
			divMultilple.style.visibility = 'hidden';
			divFulltext.style.visibility = 'visible';
			divFillBlank.style.visibility = 'hidden';
			divMatchingItems.style.visibility = 'hidden';
			divControl.style.visibility = 'hidden';
			return
			}
	else{
	if (numberObjects==0){
		divMultilple.style.visibility = 'hidden';
		divFulltext.style.visibility = 'hidden';
		divFillBlank.style.visibility = 'hidden';
		divMatchingItems.style.visibility = 'hidden';
		divControl.style.visibility = 'visible';
		return;
	}
	else{
		divControl.style.visibility = 'hidden';
		
		var objects="<p>";
//		alert(numberObjects);
		switch (QuestionType){
		case "1":
			divMultilple.style.visibility = 'visible';
			divFulltext.style.visibility = 'hidden';
			divFillBlank.style.visibility = 'hidden';
			divMatchingItems.style.visibility = 'hidden';
			var items="";
			for (var i=1; i<=numberObjects;i++){
				items+=" <span class='Span_Radio'>" +
						"<a>Item </a>" +i+":"+
						"&nbsp;&nbsp;<input class='txtQuestionItem' type = 'radio' name = 'QType' id ='txtRadio"+i+"' />" +
						"&nbsp;&nbsp;<input class='txtQuestionItem' type='text' id='txtAnswer"+i+"'/> " +
						"</span>";
			};
			objects+=items;
			objects+="</p>";
			document.getElementById("DivMultipleChoice").innerHTML=objects;
			break;
		case "2":
			divMultilple.style.visibility = 'hidden';
			divFulltext.style.visibility = 'hidden';
			divMatchingItems.style.visibility = 'hidden';
			divFillBlank.style.visibility = 'visible';
			var items="";
			for (var i=1; i<=numberObjects;i++){
				items+=" <span class='Span_Radio'>" +
						"<a class='aLittleLabel'>Paragraph </a>" +i+":"+
						"&nbsp;&nbsp;<TEXTAREA Name='txtFill"+i+"' class='txtInput' id='txtFill"+i+"'  ROWS=4 COLS=50></TEXTAREA>"+
						"<br/><a class='aLittleLabel'>Blank </a>" +i+":"+
						"&nbsp;&nbsp;<input class='txtQuestionItem' type='text' id='txtAnswer"+i+"'/> <br/>" +
						"</span>";
			};
			objects+=items;
			objects+="</p>";
			divFillBlank.innerHTML=objects;
			break;
		case "3":
			divMultilple.style.visibility = 'hidden';
			divFulltext.style.visibility = 'hidden';
			divFillBlank.style.visibility = 'hidden';
			divMatchingItems.style.visibility = 'visible';
			var items="";
			for (var i=1; i<=numberObjects;i++){
				items+=" <span class='Span_Radio'>" +
						"<a>Tuple </a>" +i+":"+
						"&nbsp;&nbsp;<input class='txtQuestionItem' type = 'text' name = 'QType' id ='txtMatching"+i+"' />" +
						"&nbsp;&nbsp;<input class='txtQuestionItem' type='text' id='txtAnswer"+i+"'/> " +
						"</span>";
			};
			objects+=items;
			objects+="</p>";
			divMatchingItems.innerHTML=objects;
			break;
		default:
			divMultilple.style.visibility = 'hidden';
			divFulltext.style.visibility = 'visible';
			divFillBlank.style.visibility = 'hidden';
			divMatchingItems.style.visibility = 'hidden';
			
			break;
		}
		}
	}
		
	}

function QuestionItemBackButton(){
	topicId=gup("TopicID");
	topic=gup("Topic");
	
	window.location.href="QuestionList.html?TopicID="+topicId+"&Topic="+topic;
}
function AddMoreQuestionItemBtn(){
	topicId=gup("TopicID");
	topic=gup("Topic");
	var type= gup("type");	
	var QID=gup('QuestionID');
	window.location.href = 'QuestionItem.html?QuestionID='+QID+'&type='+type+'&TopicID='+topicId+'&Topic='+topic;
	return;
}

function QuestionItemBackButton(){
	topicId=gup("TopicID");
	topic=gup("Topic");
	window.location.href="QuestionList.html?TopicID="+topicId+"&Topic="+topic;
}

function setUserSession(){
	  sessionStorage.setItem("userID","Lecturer1");
}
function getUserID(){
	var ireturn= sessionStorage.getItem("userID");
	if (ireturn== null)
		return "Lecturer1";
	else
		return ireturn;
	}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function include(arr, obj) {
    for(var i=0; i<arr.length; i++) {
        if (arr[i] == obj) return true;
    }
}